package com.javaoop.couese;

/**
 * 课程：JavaOOP ，山西应用科技学院信息工程学院计算机科学与技术专业 2201班
 *
 * @author by 2022010101张三
 * @user Administrator
 * @Date 2024/12/7 15:26
 * @Description 任务或用途 TODO: 定义继承点的直线类
 */
public class Line extends Point{
    private Point p;

    public Line(int x, int y, char c, Point p) {
        super(x, y, c);
        this.p = p;
    }

    public Line(Point p1,Point p2) {
        super(p1.getX(), p1.getY(), p1.getC());
        this.p = p1;
    }

    public Point getP() {
        return p;
    }

    public void setP(Point p) {
        this.p = p;
    }

    @Override
    public String toString() {
        return "Line{" +  "p=" + p +'}';
    }

    @Override
    public void draw(Canvas cv) {
        char[][] m = cv.getMatrix();
        char c = '$';
        int x = p.getX();
        int y = p.getY();
        int x0 = super.getX();
        int y0 = super.getY();
        for (int i = y0; i < y; i++) {
            for (int j = y0; j < y; j++) {
                m[i][j] = c;
            }
        }
        super.draw(cv);
    }


    public static void main(String args) {
        System.out.println("========= 直线 ========");
        Canvas cv=new Canvas(25,25,'.');
        Point p1=new Point(2,2,'s');
        Point p2=new Point(20,20,'s');
        Line l=new Line(p2,p1);
        l.draw(cv);
        cv.view();
    }
}
